

import Foundation
import SwiftyJSON

//lkm
class LoginTo: NSObject {
    
    var userid: String?;//"3998"
    var realname: String?;//""
    var nickname: String?;//"13126305452"
    var pwd_sign: String?;//"8tV2ilUqmzxMob98"
    var vip_now: Int?;//"3"
    var times: Int64?;//1476436850857
    
    //dict["data"].dictionaryObject  dict是JSON
    init?(jsons: [String: JSON]?) {
        super.init()
        
//        if(dict == nil || dict!.isEmpty){
//            return nil
//        }
        if(jsons == nil){
            return nil
        }
        
//        if(jsons?.isEmpty ?? true){
//            return LoginTo();
//        }
        
        if let dict = jsons{
            
            self.userid = dict["userid"]?.string//  as? String;//"3998"
            self.realname = dict["realname"]?.string//  as? String;//""
            self.nickname = dict["nickname"]?.string//  as? String;//"13126305452"
            self.pwd_sign = dict["pwd_sign"]?.string//  as? String;//"8tV2ilUqmzxMob98"
            self.vip_now = dict["vip_now"]?.int//  as? Int;//"3"
            self.times = dict["times"]?.int64//  as? Int64;//1476436850857
        }
    }
    
    //initToList( json:JSON(dict["huxing"] ) )  把JSON过的Any转为JSON
    //一定要是JSON要是 [Any] 的话 会装换失败，最后我还是选用这个JSON
    class func initToList(json: JSON)->[LoginTo?]{
        if let items = json.array {
            var results = [LoginTo?]()
            for item in items {
                let result = LoginTo(jsons: item.dictionary )
//                if(result != nil){//空还加个屁啊  json为“[]” 时 这是不会为空的。除非直接来了个nil
//                    results.append(result!)
//                }
                results.append(result)
            }
            return results;
        }
        return [LoginTo?]()
    }
    
    //initToList( json:JSON(dict["huxing"] ) )  把JSON过的Any转为JSON
    //一定要是JSON要是 [Any] 的话 会装换失败，最后我还是选用这个JSON
    class func initToMap(json: JSON)->Dictionary<String,LoginTo>{
        if let items = json.dictionary {
            var results = Dictionary<String,LoginTo>()//取值的时候本身就是可选类型啊,所以这里不用跟数组一样弄可选类型
            for (key, value)  in items {
                let result = LoginTo(jsons: value.dictionary )
                results[key] = result
            }
            return results;
        }
        return Dictionary<String,LoginTo>()
    }
    
    
    
}

